import { reqCategoryList, reqGetbannerList, reqFloorList } from '@/api'
//home模块小仓库
const state = {
    // state中的数据默认值别瞎写,服务器返回对象，服务器返回数组，初始值是根据接口的返回值来定的
    categoryList: [],
    // 轮播图的数据
    bannerList: [],
    // floor轮播图的数据
    floorList: []
};
const actions = {
    // 通过API里面的接口函数调用，向服务器发请求，获取服务器的数据
    async categoryList({ commit }) {
        let result = await reqCategoryList();
        if (result.status == 200) {
            commit('CATEGORYLIST', result.data.data)
        }
    },
    // 获取首页轮播图的数据
    async getBannerList({ commit }) {
        let { data } = await reqGetbannerList();
        if (data.code == 200) {
            commit('GETBANNERLIST', data.data)
        }
    },
    // 获取floor数据
    async getFloorList({commit}) {
        let {data} = await reqFloorList();
        if (data.code == 200) {
            commit('GETFLOORLIST', data.data)
        }
    }
};
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList;
    },
    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList;
    },
    GETFLOORLIST(state, floorList) {
        state.floorList = floorList;
    }
};
// 计算属性3
const getters = {};

export default {
    state,
    mutations,
    actions,
    getters
}